package com.commonlyUsedClass.BigDecimalDemo;

import java.math.BigDecimal;

/***
 * @ClassName: BigDecimalTest
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 11:14 2022/2/15
 * @version : V1.0
 */
public class BigDecimalTest {
    public static void main(String[] args) {

        //大的浮点数精确计算
        BigDecimal i1 = new BigDecimal("1.0");
        BigDecimal i2 = new BigDecimal("0.9");

        BigDecimal add = i1.add(i2);
        BigDecimal subtract = i1.subtract(i2);
        BigDecimal multiply = i1.multiply(i2);
        //除法需要指定精确到多少位,后面的参数为四舍五入
        BigDecimal divide = i1.divide(i2,6,BigDecimal.ROUND_HALF_UP);

        System.out.println(add);
        System.out.println(subtract);
        System.out.println(multiply);
        System.out.println(divide);
    }
}
